package com.lfnyxy.service.imp;
import com.lfnyxy.dao.CountryRefDao;
import com.lfnyxy.dto.DropVo;
import com.lfnyxy.entity.CountryRefEntity;
import com.lfnyxy.query.CountryRefQuery;
import com.lfnyxy.service.CountryRefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CountryRefServiceImp implements CountryRefService {
    @Autowired
    public CountryRefDao countryRefDao;

    public int CreateItem(CountryRefEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return countryRefDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(CountryRefEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return countryRefDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List<CountryRefEntity> QueryPageList(CountryRefQuery query) {
        int count = countryRefDao.QueryPageListCount(query);
        query.setTotal(count);
        if (count > 0) {
            return countryRefDao.QueryPageList(query);
        }
        return null;
    }

    public List<CountryRefEntity> QueryAll() {
        return countryRefDao.QueryAll();
    }

    public List<DropVo> QueryDrop(CountryRefQuery query) {
        return countryRefDao.QueryDrop(query);
    }

    public CountryRefEntity QueryItem(int Id) {
        if (Id > 0) {
            return countryRefDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return countryRefDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    private boolean CheckIsExist(CountryRefEntity entity) {
        if (entity != null) {
            return countryRefDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}